package com.company;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HTTPServer {
    public static final int THREAD_NUM = 10000;
    //private ServerSocket serverSocket;
    private int port;
    public HTTPServer(int port) {
        this.port = port;
    }

    public void startServer() {
        ExecutorService service = Executors.newFixedThreadPool(THREAD_NUM);
        try (ServerSocket serverSocket = new ServerSocket(port)) {
            while (true) {
                try {
                    Socket socket = serverSocket.accept();
                    Runnable runnable = new RequestHandle(socket);
                    service.submit(runnable);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        HTTPServer server = new HTTPServer(80);
        server.startServer();
    }
}
